package com.zxy.salenet.web.mapper;

import com.zxy.salenet.web.pojo.SalenetUser;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
 /**
  *   SalenetUserMapper。
     */
public interface SalenetUserMapper extends Mapper<SalenetUser> {
    /**
     * 查询是否重复存在用户id
     *
     * @param userId
     * @return
     */
    @Select("SELECT COUNT(0) FROM salenet_user WHERE user_id = #{userId}")
    Integer selectRepUserId(@Param("userId") Integer userId);

    /**
     * 查询用户名是否重复
     *
     * @param userName
     * @return
     */
    @Select(value = "SELECT COUNT(0) FROM salenet_user WHERE user_name = #{userName}")
    Integer selectRepName(@Param("userName") String userName);

    /**
     * 查询真实姓名是否重复
     *
     * @param userRealName
     * @return
     */
    @Select("SELECT COUNT(0) FROM salenet_user WHERE user_real_name = #{userRealName}")
    Integer selectRepRealName(@Param("userRealName") String userRealName);

    /**
     * 查询手机号是否重复
     *
     * @param userPhone
     * @return
     */
    @Select("SELECT COUNT(0) FROM salenet_user WHERE user_phone = #{userPhone}")
    Integer selectRepPhone(@Param("userPhone") String userPhone);

    /**
     * 添加用户
     *
     * @param salenetUser
     * @return
     */
    @Insert(value = "INSERT INTO salenet_user VALUES(default,#{userId},#{userRealName},#{userName},#{userSex},#{userAge},#{userAddress},#{userBrith},#{userPasswd},#{userPhone},#{userEmail},#{userPaypass},0)")
    Integer insertUsers(SalenetUser salenetUser);

    /**
     * 登陆
     *
     * @param userName
     * @param cryPassword
     * @return
     */
    @Select(value = "SELECT user_id as userId,user_name as userName,user_comm as userComm FROM salenet_user WHERE user_phone = #{userPhone} or user_name = #{userName}  AND user_passwd = #{cryPassword}")
    SalenetUser selectUserLoginByUserNameAndPassword(@Param("userName") String userName, @Param("userPhone") String password,@Param("cryPassword") String cryPassword);

    /**
     * 获取对应的用户信息
     *
     * @param userId
     * @param userName
     * @return
     */
    @Select(value = "SELECT * from salenet_user WHERE user_name = #{userName} AND user_id = #{userId}")
    SalenetUser selectUserMessageByUserIdAndUserName(@Param("userId") Integer userId, @Param("userName") String userName);

    /**
     * 对比支付密码是否错误
     *
     * @param userPayPass
     * @param userId
     * @return
     */
    @Select(value = "SELECT COUNT(0) FROM salenet_user WHERE user_paypass = #{userPayPass} AND user_id = #{userId}")
    Integer selectPayPassTrue(@Param("userPayPass") String userPayPass, @Param("userId") Integer userId);

    /**
     * 修改密码
     *
     * @param newUerPassword
     * @param userId
     * @return
     */
    @Update(value = "UPDATE salenet_user SET user_passwd = #{newUerPassword} WHERE user_id = #{userId}")
    Integer updatePayPassByUserId(@Param("newUerPassword") String newUerPassword, @Param("userId") Integer userId);

    /**
     * 获取所有的用户信息
     *
     * @param userName
     * @return
     */
    @Select(value = "select * from salenet_user where user_name like #{userName}")
    List<SalenetUser> queryAllUserList(@Param("userName") String userName);

    /**
     * 根据用户唯一ID删除用户信息
     *
     * @param userId
     * @return
     */
    @Delete(value = "delete from salenet_user where user_id = #{userId}")
    Integer deleteUserByUserId(@Param("userId") Integer userId);

    /**
     * 获取所有的用户id
     * @return
     */
    @Select(value = "select user_id from salenet_user")
    List<Integer> selectAllUserId();

    /**
     * 修改主要的收货地址
     * @param userId
     * @param commId
     * @return
     */
    @Update(value = "UPDATE salenet_user SET user_comm = #{commId} WHERE user_id = #{userId}")
    Integer updateCommByUserId(@Param("userId") Integer userId,@Param("commId") Integer commId);
    /**
     * 完成
     */
}